package com.linkwechat.wecom.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.enums.DelFlagEnum;
import com.linkwechat.common.enums.LoginTypeEnum;
import com.linkwechat.common.enums.UserTypeEnum;
import com.linkwechat.common.utils.*;
import com.linkwechat.common.vo.user.QwScanQrCodeLoginTokenPayloadVO;
import com.linkwechat.common.vo.user.UserLoginVO;
import com.linkwechat.domain.WeCorpAccount;
import com.linkwechat.wecom.mapper.MyWeCorpAccountMapper;
import com.linkwechat.common.component.CacheService;
import com.linkwechat.wecom.service.QwService;
import com.linkwechat.common.vo.qw.AppInfoVO;
import com.linkwechat.common.vo.qw.GetVisitUserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 王君平
 * @Date 2024/6/7 14:36
 * @Description
 */
@Slf4j
@Service
public class QwServiceImpl implements QwService {

    @Autowired
    private MyWeCorpAccountMapper weCorpAccountMapper;

    @Autowired
    private CacheService cacheService;

    @Override
    public AppInfoVO appInfo() {
        WeCorpAccount account = getWeCorpAccount();
        AppInfoVO app = new AppInfoVO();
        app.setCorpId(account.getCorpId());
        app.setAgentId(account.getAgentId());
        return app;
    }

    private WeCorpAccount getWeCorpAccount(){
        LambdaQueryWrapper query = new LambdaQueryWrapper<WeCorpAccount>().eq(WeCorpAccount::getDelFlag, DelFlagEnum.USE.getCode());
        List<WeCorpAccount> list = weCorpAccountMapper.selectList(query);
        ParamCheckUtil.collectionEmpty(list,"没有企业自建应用的信息");
        ParamCheckUtil.collectionMoreThanOne(list,"企业自建应用多过一条");
        WeCorpAccount account = list.get(0);
        return account;
    }
}
